// router/index.js

import modules from './modules'
import Vue from 'vue'
// 注意，如果打包报出错误没有找到uni-simple-router的话需要打开以下的注释
// import Router from 'uni-simple-router/index'
import Router from 'uni-simple-router'

Vue.use(Router)
//初始化
const router = new Router({
    routes: [...modules]//路由表
});

// 白名单
const whiteList = ["/pages/LoginRegistration/accountLogin/accountLogin","/pages/LoginRegistration/register/register"]

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	if(uni.getStorageSync('token')&&uni.getStorageSync('HeroicGramtoken')){
		if(to.path==="/pages/LoginRegistration/accountLogin/accountLogin"){
			next("/");
		}else{
			next()
		}
	}else{
		// 没有token进入白名单
		if(whiteList.indexOf(to.path)>-1){
			next();
		}else{
			next("/pages/LoginRegistration/accountLogin/accountLogin")
		}
	}
	// 这里可以书写逻辑

  // next()
})
// 全局路由后置守卫
router.afterEach((to, from) => {
})
export default router;
